package algorithm.leetcode;

/**
 * @author bingo
 * @Description
 * @Date 2018/6/5
 */
public class ListNode {

    public int val;

    public ListNode next;

    public ListNode(int val) {
        this.val = val;
    }
    /**
     *  将数组转换为一个链表
     * */
    public ListNode(int[] arr) {
        ListNode curNode  = null;
        for (int i = 0; i < arr.length; i++) {
            if (i == 0) {
                this.val = arr[0];
                curNode = this;
                }
            else{
                 ListNode itemNode = new ListNode(arr[i]);
                 curNode.next = itemNode;
                 curNode = curNode.next;
            }
        }
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        ListNode cur = this;
        while (cur!=null){
            stringBuilder.append(cur.val+"-->");
            cur = cur.next;
        }
        stringBuilder.append("NULL");
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,6,4,5,6,8};
        ListNode listNode = new ListNode(arr);
        System.out.println(listNode);
    }
}
